<%--
  Created by IntelliJ IDEA.
  User: wg
  Date: 2017/10/17
  Time: 8:41
  Description:
--%>
<%@ page contentType="text/html;charset=UTF-8" isELIgnored="false" errorPage="error.jsp" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>显示主页面</title>
    <link rel="stylesheet" type="text/css" href="bootstrap-3.3.7-dist/css/bootstrap.css"/>
    <script src="jquery-2.1.0.js"></script>
    <style>
        table th, table td {
            text-align: center;
        }
    </style>
</head>
<body>
<h4 class="text-center">城市信息</h4>
<div class="row">
    <div class="col-lg-offset-4 col-lg-5">
        <form class="form-inline" action="${pageContext.request.contextPath}/find" method="get">
            <div class="form-group">
                <label for="searchTxt">Country Code</label>
                <input type="text" class="form-control" id="searchTxt" name="countryCode" placeholder="CountryCode">
            </div>
            <button type="submit" class="btn btn-default">搜索</button>
        </form>
    </div>
    <div class="col-lg-1"><a class="btn btn-default">增加</a></div>

</div>


<div class="row">
    <div class="col-lg-offset-2 col-lg-8">
        <table class="table table-bordered table-striped table-condensed table-hover
                table-responsive">
            <thead>
            <tr>
                <th>Id</th>
                <th>Name</th>
                <th>CountryCode</th>
                <th>District</th>
                <th>Population</th>
                <th>Function</th>
            </tr>
            </thead>

            <tbody>
            <c:forEach items="${requestScope.page.cities}" var="city">
                <tr>
                    <td>${city.id}</td>
                    <td>${city.name}</td>
                    <td>${city.countryCode}</td>
                    <td>${city.district}</td>
                    <td>${city.population}</td>
                    <td>
                        <a href="${pageContext.request.contextPath}/findSingle?id=${city.id}&pageId=${requestScope.page.pageIndex}">修改</a>
                        |
                        <a href="javascript:void(0)" onclick="onDelete(${city.id})">删除</a>
                    </td>
                </tr>
            </c:forEach>
            </tbody>
        </table>
    </div>
</div>

<div class="row">
    <div class="col-lg-offset-2 col-lg-8 text-center">
        <c:if test="${requestScope.page.pageIndex != 0}">
            <a href="${pageContext.request.contextPath}/displayPage?pageId=0">首页</a>
            <a href="${pageContext.request.contextPath}/displayPage?pageId=${requestScope.page.pageIndex - 1}">上一页</a>
        </c:if>

        <c:if test="${requestScope.page.pageIndex != requestScope.page.totalPage}">
            <a href="${pageContext.request.contextPath}/displayPage?pageId=${requestScope.page.pageIndex + 1}">下一页</a>
            <a href="${pageContext.request.contextPath}/displayPage?pageId=${requestScope.page.totalPage}">尾页</a>
        </c:if>

        第${requestScope.page.pageIndex}页/共${requestScope.page.totalPage}页
    </div>
</div>

    <script>
        function onDelete(cityId) {
          if (window.confirm("确定删除")) {
            location.href = "${pageContext.request.contextPath}/deleteSingle?id=" + cityId + "&pageId=${requestScope.page.pageIndex}";
          }
        }
    </script>
</body>
</html>
